package com.example.jiaowuchu.jiaowuSys.dao;

import com.example.jiaowuchu.jiaowuSys.pojo.yhpojo.User;
import com.example.jiaowuchu.jiaowuSys.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {

    public User select(User user){
        try (Connection connection = DBUtil.getConnection()) {

            PreparedStatement pStmt = connection.prepareStatement("select  * from user where yhm=? and pwd=? ");
            pStmt.setString(1,user.getYhm());
            pStmt.setString(2,user.getPwd());

            ResultSet rs = pStmt.executeQuery();

            if (rs.next()) {
                String yhm = rs.getString("yhm");
                String pwd = rs.getString("pwd");
                String sfbz = rs.getString("sfbz");
                String zcsj = rs.getString("zcsj");
                String yhtx = rs.getString("yhtx");

                return new User(yhm,pwd,sfbz,zcsj,yhtx);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

}
